package com.myProject.serves.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myProject.bean.TExpert;
import com.myProject.bean.TNote;
import com.myProject.dao.ExpertDao;
import com.myProject.dao.LogDao;
import com.myProject.serves.LogSev;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

import java.util.List;

public class LogSevImpl implements LogSev {
    @Override
    public List<TNote> getNoteList(TNote tNote) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        LogDao ld = sqlSession.getMapper(LogDao.class);
        sqlSession.clearCache();
        return ld.getNoteList(tNote);
    }

    @Override
    public PageInfo<TNote> getNotePage(int pageNo, int pageSize, TNote tNote) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        LogDao ld = sqlSession.getMapper(LogDao.class);
        PageHelper.startPage(pageNo, pageSize);
        List<TNote> list = ld.getNoteList(tNote);
        PageInfo<TNote> page = new PageInfo<TNote>(list);
        SqlSessionUtil.commit();
//      sqlSession.close();
        return page;
    }

    @Override
    public boolean addLog(TNote tNote) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        LogDao ld = sqlSession.getMapper(LogDao.class);
        int x = ld.addLog(tNote);
        SqlSessionUtil.commit();
        sqlSession.close();
        return x > 0 ? true : false;
    }
}
